﻿package app.view.components.sections.russia 
{
	import app.model.RemoteProxy;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.components.guiDima.switchContent.SwitchContentTextDBase;
	import app.view.components.header.HeadMarkerBase;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * 3.3 ИСТОРИЧЕСКАЯ СПРАВКА
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class RussiaHistoryDBase extends LabeledSectionBase
	{
		
		public var historyInFace_Btn:GlamurBtnBase;
		public var eventAndDate_Btn:GlamurBtnBase;
		
		public var boxSwitch:SwitchContentTextDBase;
		public var slider:Sprite;
		public var bgdImage_1:Sprite;
		public var bgdImage_2:Sprite;
		public var bgdImage_3:Sprite;
		public var bgdImage_4:Sprite;
		public var bgdImage_5:Sprite;
		private var _slider:Image;
		private var _imageArray:Array;
		
		
		public function RussiaHistoryDBase() 
		{
			super();
		}
		
		override protected function init():void
		{
			super.init();
			
			// для области справа (тупо лень делать по другому)
			_slider = new Image(slider.width, slider.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_slider);
			_slider.x = slider.x;
			_slider.y = slider.y;
			addChild(slider);
			
			
		}
		
		
		
		private function setEvents():void
		{
			historyInFace_Btn.addEventListener(MouseEvent.CLICK, onClickHistoryBtn);
			eventAndDate_Btn.addEventListener(MouseEvent.CLICK, onClickEventAndDateBtn);
			
		}
		
		private function removeEvents():void
		{
			historyInFace_Btn.removeEventListener(MouseEvent.CLICK, onClickHistoryBtn);
			eventAndDate_Btn.removeEventListener(MouseEvent.CLICK, onClickEventAndDateBtn);
			
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			
			historyInFace_Btn.destroy();
			eventAndDate_Btn.destroy();
			
			_slider.destroy();
			removeChild(_slider);
			
			boxSwitch.destroy();
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			////trace('data!!!+++', _data.data);
			
			setParamHead(HeadMarkerBase.BGD_GREEN);
			
			historyInFace_Btn.setLang(_data.lang);
			eventAndDate_Btn.setLang(_data.lang);
			
			_imageArray = new Array();
			
			for each(var object:* in _data.data.img)
			{
				//trace('1423', RemoteProxy.DOMEN+object.image[1].image_path);
				_imageArray.push(RemoteProxy.DOMEN + object.image[1].image_path);
			}
			
			if (_imageArray.length<5) 
			{
				for (var i:int = 0; i < 5-_imageArray.length; i++) 
				{
					_imageArray.push('');
				}
			}
			
			var ar:Array = new Array();
			
			for each(var objectText:* in _data.data.txt)
			{
				//trace('text', objectText.text);
				ar.push({text:String(objectText.text).substr(1)});
			}
			
			boxSwitch.data = ar as Array;
			
			_slider.loadImage(_imageArray[0]);
			
			setEvents();
		};
		
		/**
		 * переход в раздел история в лицах
		 * @param	e
		 */
		private function onClickHistoryBtn(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_RUSSIA_FACES;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
			
			
		}
		
		/**
		 * переход в раздел события и даты (вообще на потом)
		 * @param	e
		 */
		private function onClickEventAndDateBtn(e:MouseEvent):void 
		{
			
		}
		
		
		
		
	}

}